﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace PFAGame
{
    class KamikazBoss : AMob
    {

        // sprint lorsque le joueur est proche
        const float rushDistance = 5.0f;
        float rushSpeedMultiplicator = 5.0f;
        float normalSpeed = 1.0f;

        public KamikazBoss(float x, float y)
        {
            position.X = x;
            position.Y = y;
            type = e_typeMob.KAMIKAZBOSS;
        }

        public override void init()
        {
            base.init();

            moveRightAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/Spider/SpiderRunFront"), 503, 504, 2, (int)(100 / speed), true);
            moveLeftAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/Spider/SpiderRunFront"), 503, 504, 2, (int)(100 / speed), true);
            moveUpAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/Spider/SpiderRunBack"), 503, 504, 2, (int)(100 / speed), true);
            moveDownAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/Spider/SpiderRunFront"), 503, 504, 2, (int)(100 / speed), true);

            attackRightAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/Spider/explosion"), 134, 134, 12, (int)(30 * speed), false);
            attackLeftAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/Spider/explosion"), 134, 134, 12, (int)(30 * speed), false);
            attackUpAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/Spider/explosion"), 134, 134, 12, (int)(30 * speed), false);
            attackDownAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/Spider/explosion"), 134, 134, 12, (int)(30 * speed), false);

            color = Color.Red;
            scale = 2.0f;
            radius = 0.8f;

            life = 100f;
            dammage = 40f;
            attackAnimationDuration = 0.5f;
            normalSpeed = speed;
            exp = 40;
        }

        public override void seekUpdate(GameTime gameTime)
        { 
            base.seekUpdate(gameTime);
            float distanceSquarred = target.getSquaredDistance(position);
            speed = (distanceSquarred < rushDistance * rushDistance) ? normalSpeed * rushSpeedMultiplicator : normalSpeed;
        }

        protected override void attack()
        {
            // inflige les dégats,  en fonction de la distance
            float dist = target.getSquaredDistance(position);
            float dammageMultiplicator = range / dist * dist;
            if (dammageMultiplicator > 1) //clamp les dégats sur les dégat max
                dammageMultiplicator = 1;
            target.receiveDammage(dammage * dammageMultiplicator);

            // c'est le mob kamikaz!
            life = 0;
            state = e_state.DYING;

            Kamikaz.soundInstance[Kamikaz.n++].Play();
            if (Kamikaz.n >= Kamikaz.COUNT_INSTANCE)
                Kamikaz.n = 0;
        }
    }
}
